package hotstuff

import (
	"errors"
	"hotstuffImpl/proto"
)

// 创建leaf节点
func createLeaf(parent *proto.Nod, command *proto.Command) *proto.Nod {
	return &proto.Nod{
		HighQCNode: parent,
		Command:    command,
	}
}

func matchingMsg(msg *proto.Msg, t proto.MessageType, viewNumber *proto.ViewNumber) (bool, error) {
	if msg == nil || viewNumber == nil {
		return false, errors.New("msg or viewNumber is nil")
	} else {
		return msg.GetType() == t && msg.ViewNumber.ViewNumber == viewNumber.GetViewNumber(), nil
	}

}

func matchingQC(qc *proto.QuorumSig, t proto.MessageType, number *proto.ViewNumber) (bool, error) {
	if qc == nil || number == nil {
		return false, errors.New("qc or number is nil")
	} else {
		return true, nil
	}
}

//TODO:safety and liveness checks
func safeNode(nod proto.Nod, qc *proto.QuorumSig) (bool, error) {
	panic(" not implement")
}
